#ifndef NSTACKEDWIDGET_H
#define NSTACKEDWIDGET_H
#include <QtWidgets>

class NStackedWidget : public QStackedWidget{

    Q_OBJECT

public:

    NStackedWidget(QWidget *parent = nullptr) :
    auldindex(-1)
    {
        setParent(parent);
        setAttribute(Qt::WA_TranslucentBackground, false);
    }

    void setCurrentIndex(int index){
        if (auldindex == -1)
        {
            auldindex = currentIndex();
        }
        else if (auldindex != -1 && index != currentIndex())
        {
            auldindex = currentIndex(); //skipindex != -1 判断currentindex已存在，再进行ksipindex过滤
        }
        QStackedWidget::setCurrentIndex(index);
    }

    void setCurrentWidget(QWidget *widget){
        int curindex = indexOf(widget);
        if (auldindex == -1)
        {
            auldindex = currentIndex();
        }
        else if (auldindex != -1 && curindex != currentIndex())
        {
            auldindex = currentIndex();
        }
        QStackedWidget::setCurrentWidget(widget);
    }

    void backview(){
        setCurrentIndex(auldindex);
    }

private:
    int auldindex;

};
#endif
